package com.jichaoyun.sys.controller;


import com.jichaoyun.common.model.PagedResult;
import com.jichaoyun.common.model.Result;
import com.jichaoyun.model.app.vos.OperateCardsVo;

import com.jichaoyun.model.entity.Fault;
import com.jichaoyun.model.vo.FaultFormVo;
import com.jichaoyun.model.vo.FaultParaVo;
import com.jichaoyun.model.vo.FaultUploadVo;
import com.jichaoyun.sys.service.impl.FaultServiceImpl;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = {"(app)故障处理接口"})
@RequestMapping("/sys/FaultHandle")
public class FaultController {

    @Autowired
    private FaultServiceImpl faultService;

    @ApiOperation(value = "按照条件查询所有的故障记录",notes = "" +
            "")
    @GetMapping("/getMenuListPage")
    public Result<PagedResult> getMenuListPage(FaultParaVo faultParaVo){

       PagedResult pagedResult =   faultService.getMenuListPage(faultParaVo);

        return Result.success(pagedResult);
    }


    @ApiOperation(value = "获取故障的通知信息")
    @GetMapping("/getFaultInformList")
    public Result<List<FaultFormVo>> getFaultInformList(){
        List<FaultFormVo> res =   faultService.getFaultInformList();
        return Result.success(res);
    }


    @ApiOperation(value = "（app）实时概况，获取当日故障类型和待处理的情况")
    @GetMapping("/getTodayFaultInfo")
    public Result<Map<String,Integer>> getTodayFaultInfo(){
        Map<String, Integer> resMap = new HashMap<>();
        resMap =  faultService.getTodayFaultInfo();
        return Result.success(resMap);
    }

    @ApiOperation(value = "app实时概况，故障详情")
    @GetMapping("/getTodayFaultDetail")
    public Result<List<Map<String,Object>>> getTodayFaultDetail(){
        List<Map<String,Object>> resMap = new ArrayList<>();
        resMap =  faultService.getTodayFaultDetail();
        return Result.success(resMap);
    }

    @ApiOperation(value = "（app）故障处理，故障查询")
    @GetMapping("/getFaultOperateCards")
    public Result<List<OperateCardsVo>> getFaultOperateCards(){
        List<OperateCardsVo> resMap = new ArrayList<>();
        resMap =  faultService.getFaultOperateCards();
        return Result.success(resMap);
    }

    @ApiOperation(value = "（app）故障处理，点击处理之后的回显")
    @GetMapping("/getFaultOperateVo")
    public Result<Fault> getFaultOperateVo(Integer id){
        Fault fault = new Fault();
        fault =  faultService.getFaultOperateVo(id);
        return Result.success(fault);
    }


    @ApiOperation(value = "（app）故障处理，点击处理之后的保存，这里用postman测试")
    @PostMapping("/getFaultUpdate")
    public Result<String> getFaultUpdate( Integer id , String operateInfo, String operatePeople ,@RequestPart("files") List<MultipartFile> files ){
        Boolean res =  faultService.faultOperate(files,operateInfo,operatePeople,id);
        if(res){
            return Result.success("保存成功");
        }
        return Result.success("保存失败");
    }

    @ApiOperation(value = "（app）故障处理，故障排行")
    @GetMapping("/getFaultRank")
    public Result<List<Map<String,Object>>> getFaultRank(){
        List<Map<String,Object>> res = faultService.getFaultRank();
        return Result.success(res);
    }


    @ApiOperation(value = "（app）故障上传,此处用postman测试，swagger有问题")
    @PostMapping("/getFaultUpload")
    public Result<Integer> getFaultUpload(String site,String lineName,String type,
           String  description ,String status,String uploadMan){
        FaultUploadVo faultUploadVo = new FaultUploadVo();
        faultUploadVo.setSite(site);
        faultUploadVo.setLineName(lineName);
        faultUploadVo.setType(type);
        faultUploadVo.setDescription(description);
        faultUploadVo.setStatus(status);
        faultUploadVo.setUploadMan(uploadMan);

        Integer res =  faultService.faultUpload(faultUploadVo);
        if(res==-1) return Result.fail(-1);
        else return Result.success(res);
    }

    @ApiOperation(value = "（app）根据故障编号，给故障上传图片")
    @PostMapping("/getFaultUploadPic")
    public Result<Integer> getFaultUpload(Integer num, @RequestPart("files") MultipartFile files){

        Boolean res =  faultService.faultUpload(files,num);
        if(res) return Result.success();
        else return Result.fail();
    }



    @ApiOperation(value = "(app)按照条件查询所有的故障记录",notes = "" +
            "")
    @GetMapping("/getAppFaultList")
    public Result<PagedResult> getAppFaultList(FaultParaVo faultParaVo){

        PagedResult pagedResult =   faultService.getAppFaultList(faultParaVo);

        return Result.success(pagedResult);
    }



}
